<template>
  <div class="songsheet">
    <div class="sheetinfo" v-for="item in playlists" :key="item.id" @click="toPlayListPage(item.id)">
      <div class="left">
        <img :src="item.coverImgUrl" />
        <span class="name">{{ item.name }}</span>
      </div>
      <span class="trackCount">{{ item.trackCount }}首</span>
      <div class="nickname">
        <span>by </span>
        <span>{{item.creator.nickname }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { getCloudSearch } from '../../network/search.js'
export default {
  props: ['type', 'value'],
  data () {
    return {
      playlists: [],
      playlistCount: 0
    }
  },
  methods: {
    toPlayListPage (id) {
      this.$router.push('/songs/' + id)
    },
    getCloudSearch (type, keywords) {
      getCloudSearch(type, keywords).then(res => {
        // console.log(res.data)
        this.playlists = res.data.result.playlists
        this.playlistCount = res.data.result.playlistCount
        this.$emit('singerCount', this.playlistCount + ' 个歌单')
        // console.log(this.playlists)
      })
    }
  },
  created () {
    this.getCloudSearch(this.type, this.value)
  },
  watch: {
    value (newVal, oldVal) {
      // console.log('新关键词:' + newVal)
      this.value = newVal
      this.getCloudSearch(this.type, this.value)
    }
  }
}
</script>

<style lang="less" scoped>
  .sheetinfo {
    width: 100%;
    padding: 15px;
    display: flex;
    flex-direction: row;
    align-items: center;
    .left {
      display: flex;
      flex-direction: row;
      align-items: center;
      width: 50%;
      img {
        width: 75px;
        height: 75px;
        border-radius: 5px;
        margin-right: 15px;
      }
    }
    .trackCount {
      width: 20%;
      color: #b3b3b3;
    }
    .nickname {
      width: 30%;
      span:first-child {
        color: #c8c8c8;
      }
    }
  }
  .sheetinfo:nth-child(2n) {
    background-color: #f9f9f9;
  }
  .sheetinfo:hover {
    background-color: #f0f1f2;
  }
</style>
